//
//  ZYNotificationCenter.h
//  Example
//
//  Created by wzp on 2024/8/21.
//

#import <Foundation/Foundation.h>
#import "ZYNotifyClient.h"

#define NotifyClient(protocolName, sel, func) \
{ \
    NSArray *clientList = [[ZYNotificationCenter shareInstance] clientsWithKey:@protocol(protocolName)]; \
    for (ZYNotifyClient *client in clientList) { \
        if ([client.obj respondsToSelector:sel]) { \
            [client func]; \
        } \
    } \
}

#define AddNotificationClient(client, protocolName) [[ZYNotificationCenter shareInstance] addClient:client protocol:@protocol(protocolName)]

#define RemoveAllNotificationClient(client) [[ZYNotificationCenter shareInstance] removeAllForClient:client]


NS_ASSUME_NONNULL_BEGIN

@interface ZYNotificationCenter : NSObject
+ (instancetype)shareInstance;

- (void)addClient:(id)client protocol:(Protocol*)protocol;
- (void)removeAllForClient:(id)client;
- (void)removeClient:(id)client forProtocol:(Protocol *)ptl;
- (NSArray<ZYNotifyClient *> *)clientsWithKey:(nonnull Protocol *)ptl;
@end

NS_ASSUME_NONNULL_END
